package Chapter08.smallchange;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Scanner;

/**
 * @author 杨森
 * @date 2022年10月08日 18:06
 */
public class SmallChangeSys {
    public static void main(String[] args) {
//        定义相关的变量
        boolean loop = true;
        Scanner scanner = new Scanner(System.in);
        String key = "";
//        完成零钱通明细
        String details="-------------零钱通明细-------------";

//        完成收益入账
        double money=0;
        double balance=0;
        Date date=null;

//        消费
        String note="";
        SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm");
        do {
            System.out.println("=============零钱通菜单=============");
            System.out.println("\t\t\t1 零钱通明细");
            System.out.println("\t\t\t2 收益入账");
            System.out.println("\t\t\t3 消费");
            System.out.println("\t\t\t4 退出");

            System.out.println("请选择（1-4）:");
            key = scanner.next();

//            使用Switch分支控制
            switch (key) {
                case "1":
                    System.out.println(details);
                    break;
                case "2":
                    System.out.println("收益入账金额：");
                    money = scanner.nextDouble();

                    if (money<=0){
                        System.out.println("收益入账金额范围需要大于0");
                        break;
                    }
                    balance+=money;
                    date=new Date();
                    details+="\n收益入账\t"+money+"\t"+sdf.format(date)+"\t"+balance;
                    break;
                case "3":
                    System.out.println("消费金额：");
                    money= scanner.nextDouble();
                    if (money>balance||money<=0){
                    System.out.println("您的消费金额应该在0-"+balance);
                    break;
                }
                    System.out.println("消费说明：");
                    note=scanner.next();

                    balance -= money;
                    date=new Date();
                    details+="\n"+note+"\t-"+money+"\t"+sdf.format(date)+"\t"+balance;

                    break;
                case "4":
                    System.out.println("4 退出");
                    String choice="";

                    while (true){
                        System.out.println("您确定要退出么？Y/N");
                        choice= scanner.next();
                        if ("Y".equals(choice)||"N".equals(choice)) {
                            break;
                        }

                    }
                    if(choice.equals("Y")){
                        loop=false;
                    }
                    break;
                default:
                    System.out.println("选择有误，请重新选择");
            }
        } while (loop);
        System.out.println("-------------退出了零钱通-------------");
    }
}
